package com.ruoyi.project.system.holder.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.holder.domain.Holder;
import com.ruoyi.project.system.holder.service.IHolderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 持有人Controller
 * 
 * @author xn
 * @date 2024-10-07
 */
@Controller
@RequestMapping("/system/holder")
public class HolderController extends BaseController
{
    private String prefix = "system/holder";

    @Autowired
    private IHolderService holderService;

    @RequiresPermissions("system:holder:view")
    @GetMapping()
    public String holder()
    {
        return prefix + "/holder";
    }

    /**
     * 查询持有人列表
     */
    @RequiresPermissions("system:holder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Holder holder)
    {
        startPage();
        List<Holder> list = holderService.selectHolderList(holder);
        return getDataTable(list);
    }

    /**
     * 导出持有人列表
     */
    @RequiresPermissions("system:holder:export")
    @Log(title = "持有人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Holder holder)
    {
        List<Holder> list = holderService.selectHolderList(holder);
        ExcelUtil<Holder> util = new ExcelUtil<Holder>(Holder.class);
        return util.exportExcel(list, "持有人数据");
    }

    /**
     * 新增持有人
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存持有人
     */
    @RequiresPermissions("system:holder:add")
    @Log(title = "持有人", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Holder holder)
    {
        return toAjax(holderService.insertHolder(holder));
    }

    /**
     * 修改持有人
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Holder holder = holderService.selectHolderById(id);
        mmap.put("holder", holder);
        return prefix + "/edit";
    }

    /**
     * 修改保存持有人
     */
    @RequiresPermissions("system:holder:edit")
    @Log(title = "持有人", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Holder holder)
    {
        return toAjax(holderService.updateHolder(holder));
    }

    /**
     * 删除持有人
     */
    @RequiresPermissions("system:holder:remove")
    @Log(title = "持有人", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(holderService.deleteHolderByIds(ids));
    }
}
